package orm

import (
	"fmt"
)

// 大于条件
type condGt struct {
	field string
	value interface{}
}

// 小于等于条件
type condLe struct {
	field string
	value interface{}
}

// 大于
func Gt(field string, value interface{}) Cond {
	return &condGt{
		field: field,
		value: value,
	}
}

// 小于等于
func Le(field string, value interface{}) Cond {
	return &condLe{
		field: field,
		value: value,
	}
}

func (c *condGt) Not() Cond {
	return Le(c.field, c.value)
}

func (c *condLe) Not() Cond {
	return Gt(c.field, c.value)
}

func (c *condGt) Gen(args *[]interface{}, param func() string, colname func(string) string) string {
	*args = append(*args, c.value)
	return fmt.Sprintf("%v > %v", colname(c.field), param())
}

func (c *condLe) Gen(args *[]interface{}, param func() string, colname func(string) string) string {
	*args = append(*args, c.value)
	return fmt.Sprintf("%v <= %v", colname(c.field), param())
}
